<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="检测单位名称
" prop="jiancdwmc">
        <el-input v-model="queryParams.jiancdwmc" placeholder="请输入检测单位名称
" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工程名称
" prop="gongcmc">
        <el-input v-model="queryParams.gongcmc" placeholder="请输入工程名称
" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="工程部位/用途
" prop="gongcbwyt">
        <el-input v-model="queryParams.gongcbwyt" placeholder="请输入工程部位/用途
" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="样品信息
" prop="yangpxx">
        <el-input v-model="queryParams.yangpxx" placeholder="请输入样品信息
" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="样品信息id
" prop="yangpxxid">
        <el-input v-model="queryParams.yangpxxid" placeholder="请输入样品信息id
" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="试验检测日期
" prop="shiyjcrq">
        <el-date-picker clearable v-model="queryParams.shiyjcrq" type="date" value-format="yyyy-MM-dd" placeholder="请选择试验检测日期
"></el-date-picker>
      </el-form-item>
      <el-form-item label="试验条件
" prop="shiytj">
        <el-input v-model="queryParams.shiytj" placeholder="请输入试验条件
" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="检测依据
" prop="jiancyj">
        <el-input v-model="queryParams.jiancyj" placeholder="请输入检测依据
" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="判定依据
" prop="pandyj">
        <el-input v-model="queryParams.pandyj" placeholder="请输入判定依据
" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="主要仪器设备名称及编号
" prop="zhuyyqsbmcjbh">
        <el-input v-model="queryParams.zhuyyqsbmcjbh" placeholder="请输入主要仪器设备名称及编号
" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb5 top-right-btn small-line-height">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['report_lq:lqLqdlsybgBsInfo:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate" v-hasPermi="['report_lq:lqLqdlsybgBsInfo:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete" v-hasPermi="['report_lq:lqLqdlsybgBsInfo:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['report_lq:lqLqdlsybgBsInfo:export']">导出</el-button>
      </el-col>
      <!-- <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> -->
    </el-row>

    <el-table border stripe v-loading="loading" :data="lqLqdlsybgBsInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="表ID" align="center" prop="excelId" v-if="true" />
      <el-table-column label="检测单位名称
" align="center" prop="jiancdwmc" />
      <el-table-column label="工程名称
" align="center" prop="gongcmc" />
      <el-table-column label="工程部位/用途
" align="center" prop="gongcbwyt" />
      <el-table-column label="样品信息
" align="center" prop="yangpxx" />
      <el-table-column label="样品信息id
" align="center" prop="yangpxxid" />
      <el-table-column label="试验检测日期
" align="center" prop="shiyjcrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.shiyjcrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="试验条件
" align="center" prop="shiytj" />
      <el-table-column label="检测依据
" align="center" prop="jiancyj" />
      <el-table-column label="判定依据
" align="center" prop="pandyj" />
      <el-table-column label="主要仪器设备名称及编号
" align="center" prop="zhuyyqsbmcjbh" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['report_lq:lqLqdlsybgBsInfo:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['report_lq:lqLqdlsybgBsInfo:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改沥青道路石油报告对话框 -->
    <jy-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="检测单位名称
" prop="jiancdwmc">
          <el-input v-model="form.jiancdwmc" placeholder="请输入检测单位名称
" />
        </el-form-item>
        <el-form-item label="工程名称
" prop="gongcmc">
          <el-input v-model="form.gongcmc" placeholder="请输入工程名称
" />
        </el-form-item>
        <el-form-item label="工程部位/用途
" prop="gongcbwyt">
          <el-input v-model="form.gongcbwyt" placeholder="请输入工程部位/用途
" />
        </el-form-item>
        <el-form-item label="样品信息
" prop="yangpxx">
          <el-input v-model="form.yangpxx" placeholder="请输入样品信息
" />
        </el-form-item>
        <el-form-item label="样品信息id
" prop="yangpxxid">
          <el-input v-model="form.yangpxxid" placeholder="请输入样品信息id
" />
        </el-form-item>
        <el-form-item label="试验检测日期
" prop="shiyjcrq">
          <el-date-picker clearable v-model="form.shiyjcrq" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择试验检测日期
"></el-date-picker>
        </el-form-item>
        <el-form-item label="试验条件
" prop="shiytj">
          <el-input v-model="form.shiytj" placeholder="请输入试验条件
" />
        </el-form-item>
        <el-form-item label="检测依据
" prop="jiancyj">
          <el-input v-model="form.jiancyj" placeholder="请输入检测依据
" />
        </el-form-item>
        <el-form-item label="判定依据
" prop="pandyj">
          <el-input v-model="form.pandyj" placeholder="请输入判定依据
" />
        </el-form-item>
        <el-form-item label="主要仪器设备名称及编号
" prop="zhuyyqsbmcjbh">
          <el-input v-model="form.zhuyyqsbmcjbh" placeholder="请输入主要仪器设备名称及编号
" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button size="small" @click="cancel">取 消</el-button>
      </div>
    </jy-dialog>
  </div>
</template>

<script>
import { listLqLqdlsybgBsInfo, getLqLqdlsybgBsInfo, delLqLqdlsybgBsInfo, addLqLqdlsybgBsInfo, updateLqLqdlsybgBsInfo } from "@/api/report_lq/lqLqdlsybgBsInfo";

export default {
  name: "LqLqdlsybgBsInfo",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 沥青道路石油报告表格数据
      lqLqdlsybgBsInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        jiancdwmc: undefined,
        gongcmc: undefined,
        gongcbwyt: undefined,
        yangpxx: undefined,
        yangpxxid: undefined,
        shiyjcrq: undefined,
        shiytj: undefined,
        jiancyj: undefined,
        pandyj: undefined,
        zhuyyqsbmcjbh: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        jiancyj: [{ required: true, message: "检测依据不能为空", trigger: "blur" }]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询沥青道路石油报告列表 */
    getList() {
      this.loading = true;
      listLqLqdlsybgBsInfo(this.queryParams).then((response) => {
        this.lqLqdlsybgBsInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        excelId: undefined,
        jiancdwmc: undefined,
        gongcmc: undefined,
        gongcbwyt: undefined,
        yangpxx: undefined,
        yangpxxid: undefined,
        shiyjcrq: undefined,
        shiytj: undefined,
        jiancyj: undefined,
        pandyj: undefined,
        zhuyyqsbmcjbh: undefined,
        delFlag: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.excelId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加沥青道路石油报告";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const excelId = row.excelId || this.ids;
      getLqLqdlsybgBsInfo(excelId).then((response) => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改沥青道路石油报告";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.excelId != null) {
            updateLqLqdlsybgBsInfo(this.form)
              .then((response) => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          } else {
            addLqLqdlsybgBsInfo(this.form)
              .then((response) => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              })
              .finally(() => {
                this.buttonLoading = false;
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const excelIds = row.excelId || this.ids;
      this.$modal
        .confirm('是否确认删除沥青道路石油报告编号为"' + excelIds + '"的数据项？')
        .then(() => {
          this.loading = true;
          return delLqLqdlsybgBsInfo(excelIds);
        })
        .then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {})
        .finally(() => {
          this.loading = false;
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "report_lq/lqLqdlsybgBsInfo/export",
        {
          ...this.queryParams
        },
        `lqLqdlsybgBsInfo_${new Date().getTime()}.xlsx`
      );
    }
  }
};
</script>
